<template>
	<div style="display: flex;">
		<div style="width: 77%;">
			<h4>教学安排</h4>
			<hr >
			<table  style="width: 100%;">
				<tr>
					<td>教师ID</td>
					<td>教师名称</td>
					<td>班级ID</td>
					<td>班级名称</td> 
					<td>课程ID</td>
					<td>课程名称</td>
					<td>删除</td>
				</tr>
				<tr v-for="t in tasks" style="line-height: 36px;">
					<td>{{t.user.uid}}</td>
					<td>{{t.user.uname}}</td>
					<td>{{t.clz.clzno}}</td>
					<td>{{t.clz.clzname}}</td>
					<td>{{t.course.cno}}</td>
					<td>{{t.course.cname}}</td>
					<td><button @click="doDel(t.kid)">del</button></td>
				</tr>
			</table>
		</div>
		<hr >
		<div style="width: 20%;">
			<h4>添加-表单录入</h4>
			<table style="line-height: 36px;">
			<tr>
				<td>教师:</td>
			    <td><select style="width: 120px;" v-model="task.user.uid">
				<option v-for="u in teas" 
				v-bind:value="u.uid">
			    {{u.uname}}
				</option></select></td>
			</tr>
			<tr>
			    <td>班级:</td>
			    <td><select style="width: 120px;" v-model="task.clz.clzno">
			    <option v-for="o in clzs"
			    v-bind:value="o.clzno">
			    {{o.clzname}}
			    </option></select></td>
			</tr>
			<tr>
			    <td>课程:</td>
			    <td><select style="width: 120px;" v-model="task.course.cno">
			    <option v-for="c in cous"
			    v-bind:value="c.cno">
			    {{c.cname}}
			    </option>
			    </select></td>
			</tr>
			<tr>
			    <td></td>
			    <td><button @click="doAdd()">录入排课</button></td>
			</tr>
			</table>
		</div>
		
	</div>
</template>

<script setup>
	import axios from 'axios';
</script>
<script>
	export default{
		data(){
			return{
				tasks :[],
				task :{
					user :{uid : 0},
					clz : {clzno : ''},
					course :{cno :''},
					},
				clzs :[],
				cous :[],
				teas :[]
			}
		},
		methods:{
			doAdd(){
				console.log("Task添加");console.log(this.task);

				this.$postj("/api/adm/task/add",this.task
				).then((resp)=>{
					console.log(resp.data.data);
					this.tasks = resp.data.data;
				})
			},
			doDel(kid){
				console.log("Task删除"); console.log("kid："+kid);
				let that = this;
				let token = window.localStorage.getItem("token");
				
				this.$axios.get(this.$ip+"/api/adm/task/del/"+kid,
				{headers : {'Authorization':
				'Bearer '+token}}
				).then(function(resp){
					console.log(resp.data.data);
					that.tasks = resp.data.data;
				})
			},
			findAllCou(){
				console.log("课程下拉框");
				
				this.$get("/api/adm/course/findAll"
				).then((resp)=>{
				console.log(resp.data);
				this.cous = resp.data.data;
				})
			},
			findAllClz(){
				console.log("班级下拉框");
				
				this.$get("/api/adm/clz/findAll"
				).then((resp)=>{
				console.log(resp.data);
				this.clzs = resp.data.data;
				})
			},
			findAllTea(){
				console.log("教师下拉框");
				
				this.$get("/api/adm/tea/findAll"
				).then((resp)=>{
				console.log(resp.data);
				this.teas = resp.data.data;
				})
			},
			findAll(){
				console.log("Task准备显示");

				this.$get("/api/adm/task/findAll"
				).then((resp)=>{
					console.log(resp.data.data);
					this.tasks = resp.data.data;
				})
			}
		},
		mounted() {
			console.log("初始化加载数据....");
			this.findAll();
			this.findAllTea();
			this.findAllClz();
			this.findAllCou();
		}
	}
</script>

<style>
</style>
